// Global variables
int X, Y;
int step = 2;
int direction = RIGHT;
int screen_x = 150;
int screen_y = 150;
int o_w = 30;

// Setup the Processing Canvas
void setup(){
  size( screen_x, screen_y );
  strokeWeight( 5 );
  frameRate( 24 );
  X = 0;
  Y = 0;
  background( 100 );
  stroke(0,200,100);
}

// Main draw loop
void draw(){	
	clear();
	run();
}


// Set circle's next destination
/*void mouseMoved(){
  nX = mouseX;
  nY = mouseY;  
}
*/

void keyPressed() {
	direction = keyCode; 	
}

function clear()
{
	background( 100 );
}

function run()
{
	switch(direction)
	{
		case UP:
			if(Y != 0)
				Y -= step;
			break;
		case DOWN:
			if(Y != screen_y - o_w - 2)
				Y += step;			
			break;
		case LEFT:
			if(X != 0)
				X -= step;	
			break;
		case RIGHT:
			if(X != screen_x - o_w - 2)
				X += step;			
			break;
	}	
	
	rect(X, Y, o_w, o_w);
}